import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { PostService } from './post.service';
import { CreatePostDto, UpdatePostDto } from './dto/post.dto';
import { ApiTags } from '@nestjs/swagger';
import { AdminPostPageDto } from './dto/admin-post.dto';
import { JwtPass } from '@/core/decorator';

@ApiTags('后台/文章')
@Controller('admin/post')
export class AdminPostController {
  constructor(
    private readonly postService: PostService,
  ) {}
  /**
   * 文章创建
   */
  @JwtPass()
  @Post()
  async create(@Body() data: CreatePostDto) {
    await this.postService.create(data);
  }

  /**
   * 文章列表
   */
  @Get()
  postList(@Query() query: AdminPostPageDto) {
    return this.postService.findPage(query);
  }

  /**
   * 文章详情
   */
  @Get(':postId')
  postDetail(@Param('postId') postId: number) {
    return this.postService.findOne(postId);
  }

  /**
   * 文章更新
   */
  @Patch(':postId')
  async update(
    @Param('postId') postId: number,
    @Body() updatePostDto: UpdatePostDto,
  ) {
    await this.postService.update(postId, updatePostDto);
  }

  /**
   * 文章删除
   */
  @Delete(':postId')
  async remove(@Param('postId') postId: number) {
    await this.postService.fakeRemove(postId);
  }
}
